function webApiClass() {
    this.preUrl = "https://yiligame.jvlihd.cn/api/index/";
    // this.preUrl = "./resource/api/";
    this.isDebug = false;
    this.send = false;
}

webApiClass.prototype.init = function(data,calBack)
{
    var _self = this;
    if(_self.send) return;
    _self.send = true;
    var suffix = this.isDebug ? ".json" : ""
    var url = _self.preUrl + "init"+suffix;
    //0 发送失败  1发送成功
    $.post(url,data,function (res) {
        _self.send = false;
        if(_self.isDebug)
        {
            calBack && calBack(res);
        }else{
            calBack && calBack(res.data);
        }
    },"json")
};



//游戏通关提交数据
webApiClass.prototype.pass = function(data,calBack)
{
    var _self = this;
    if(_self.send) return;
    _self.send = true;
    var suffix = this.isDebug ? ".json" : ""
    var url = _self.preUrl + "pass"+suffix;
    data.token     = window.config.userInfo.token;
    //0 发送失败  1发送成功
    $.post(url,data,function (res) {
        _self.send = false;
        if(_self.isDebug)
        {
            calBack && calBack(res);
        }else{
            calBack && calBack(res.data);
        }
    },"json")
};


//抽奖
webApiClass.prototype.getPrize = function(data,calBack)
{
    var _self = this;
    if(_self.send) return;
    _self.send = true;
    var suffix = this.isDebug ? ".json" : ""
    var url = _self.preUrl + "getPrize"+suffix;
    var tishi = layer.load(1, {
        icon: 1,
        shade: [0.3,'#000'],
    });
    data.token     = window.config.userInfo.token;
    $.post(url,data,function (res) {
        _self.send = false;
        layer.close(tishi);
        if(_self.isDebug)
        {
            calBack && calBack(res);
        }else{
            calBack && calBack(res.data);
        }
    },"json")
};

//获取中奖列表
webApiClass.prototype.getPrizes = function(data,calBack)
{
    var _self = this;
    if(_self.send) return;
    _self.send = true;
    var suffix = this.isDebug ? ".json" : ""
    var url = _self.preUrl + "getPrizes"+suffix;
    var tishi = layer.load(1, {
        icon: 1,
        shade: [0.3,'#000'],
    });
    data.token     = window.config.userInfo.token;
    $.post(url,data,function (res) {
        _self.send = false;
        layer.close(tishi);
        if(_self.isDebug)
        {
            calBack && calBack(res);
        }else{
            calBack && calBack(res.data);
        }
    },"json")
};

//获取单个奖品数据
webApiClass.prototype.getPrizeById = function(data,calBack)
{
    var _self = this;
    if(_self.send) return;
    _self.send = true;
    var suffix = this.isDebug ? ".json" : ""
    var url = _self.preUrl + "getPrizeById"+suffix;
    var tishi = layer.load(1, {
        icon: 1,
        shade: [0.3,'#000'],
    });
    data.token     = window.config.userInfo.token;
    $.post(url,data,function (res) {
        _self.send = false;
        layer.close(tishi);
        if(_self.isDebug)
        {
            calBack && calBack(res);
        }else{
            calBack && calBack(res.data);
        }
    },"json")
};

//提交中奖数据
webApiClass.prototype.submite = function(data,calBack)
{
    var _self = this;
    if(_self.send) return;
    _self.send = true;
    var suffix = this.isDebug ? ".json" : ""
    var url = _self.preUrl + "submite"+suffix;
    var tishi = layer.load(1, {
        icon: 1,
        shade: [0.3,'#000'],
    });
    data.token     = window.config.userInfo.token;
    $.post(url,data,function (res) {
        _self.send = false;
        layer.close(tishi);
        if(_self.isDebug)
        {
            calBack && calBack(res);
        }else{
            calBack && calBack(res.data);
        }
    },"json")
};


window.webApi = new webApiClass();


var IV = '8NONwyJtHesysWpM';
var KEY = '1234567898882222';
// var data = 'ABCDEFGH';

// 加密
function encrypt(str) {
    var key = CryptoJS.enc.Utf8.parse(KEY);
    var iv = CryptoJS.enc.Utf8.parse(IV);
    var encrypted = CryptoJS.AES.encrypt(str,key,{iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});
    return encrypted.toString();
}


function isPoneAvailable(poneInput) {
    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(poneInput)) {
        return false;
    } else {
        return true;
    }
}

